﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using FlyHorse.LIMS.Model;

namespace FlyHorse.LIMS.WinApp.DataManageForms.ReportProductForms
{
    public partial class FillDataForm : DevExpress.XtraEditors.XtraForm
    {
        BLL.ReportSemiBll semiBll = new BLL.ReportSemiBll();
        BLL.ToolBll toolBll = new BLL.ToolBll();
        private Action<ReportSemi> _FillDataSemi;
        private Action<ReportMix> _FillDataMix;

        public FillDataForm(Action<ReportSemi> FillDataMethod)   //填充过程数据
        {
            InitializeComponent();
            _FillDataSemi = FillDataMethod;
        }

        public FillDataForm(Action<ReportMix> FillDataMethod)  //填充成品数据
        {
            InitializeComponent();
            _FillDataMix = FillDataMethod;
        }


       

        private void FillDataForm_Load(object sender, EventArgs e)
        {
            //绑定grid里的样品名称
            //repositoryItemLookUpEdit1.DataSource = toolBll.GetAllGoodList();
            ////绑定grid里的取样位置
            //repositoryItemLookUpEdit2.DataSource = toolBll.GetAllSamplingPlaceList();

            this.gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
            this.gridView1.OptionsBehavior.Editable = false;
            this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;

            //this.gridView2.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
            //this.gridView2.OptionsBehavior.Editable = false;
            //this.gridView2.OptionsSelection.EnableAppearanceFocusedCell = false;
        }
        private void barEditItem_Date_EditValueChanged(object sender, EventArgs e)
        {
            DateTime date = Convert.ToDateTime(this.barEditItem_Date.EditValue);
            DateTime yesterday = date.AddDays(-1);
            DateTime tomorrow = date.AddDays(1);

            var dataList = semiBll.LoadEntities(m => m.SendDate >= date && m.SendDate < tomorrow).ToList();
            this.gridControl1.DataSource = dataList;
        }

        private void barLargeButton_submit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.gridView1.GetFocusedRowCellValue("ReportSemiID")!=null)
            {
                string id = Convert.ToString(this.gridView1.GetFocusedRowCellValue("ReportSemiID"));
                ReportSemi report = semiBll.LoadEntities(m => m.ReportSemiID == id).FirstOrDefault();
                if (report!=null)
                {
                    _FillDataSemi(report);
                }

            }
        }
      


    }
}